package com.jjb.www.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.glide.GlideApp;

/**
 * Author: crg
 * time:   2021/9/10 14:12
 * des:    打卡详情适配器
 */
public class PunchDetailAdapter extends AppAdapter<String> {

    public PunchDetailAdapter(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView mTvPunchTime;
        private final ShapeTextView mTvPunchNormal;
        private final ShapeTextView mTvPunchMissingCard;
        private final ShapeTextView mTvPunchUnderReview;
        private final LinearLayout mLlTurnDown;
        private final TextView mReason;
        private final TextView mTvClassTime;
        private final AppCompatImageView mIvHaveAClass;
        private final View mLine1;
        private final View mLine2;

        private ViewHolder() {
            super(R.layout.item_p_clock);
            mTvPunchTime = findViewById(R.id.tv_punch_time);
            mTvPunchNormal = findViewById(R.id.tv_punch_normal);
            mTvPunchMissingCard = findViewById(R.id.tv_punch_missing_card);
            mTvPunchUnderReview = findViewById(R.id.tv_punch_under_review);
            mLlTurnDown = findViewById(R.id.ll_turn_down);
            mLine1 = findViewById(R.id.view_line1);
            mLine2 = findViewById(R.id.view_line2);
            mTvClassTime = findViewById(R.id.tv_class_time);
            mIvHaveAClass = findViewById(R.id.iv_have_a_class);
            mReason = findViewById(R.id.tv_reason_for_rejection);
        }

        @SuppressLint("SetTextI18n")
        @Override
        public void onBindView(int position) {
            mLine1.setVisibility(position == 0 ? View.INVISIBLE : View.VISIBLE);
            mLine2.setVisibility(position == getCount() - 1 ? View.GONE : View.VISIBLE);
            mTvPunchNormal.setVisibility(View.GONE);
            mTvPunchMissingCard.setVisibility(View.GONE);
            mTvPunchUnderReview.setVisibility(View.GONE);
            mLlTurnDown.setVisibility(View.GONE);
            mReason.setVisibility(View.GONE);
//            PunchListApi.Bean.ItemsDTO.PunchListDTO classInfo = getItem(position);
//            //打卡类型（1=上课，2=下课，3=实操）,可用值:1,2,3
//            if (classInfo.getType() == 3) {
//                mTvClassTime.setText("时间 " + classInfo.getCourseHourTime());
//            } else {
//                mTvClassTime.setText((classInfo.getType() == 1 ? "上课时间  " : "下课时间  ") + classInfo.getCourseHourTime());
//            }
//            mTvPunchTime.setText(TextUtils.isEmpty(classInfo.getTime()) ? "打卡时间  无" : "打卡时间  " + classInfo.getTime());
//            //打卡状态(1=正常，2=缺卡,3=补卡审核中,4=补卡驳回)
//            switch (classInfo.getStatus()) {
//                case 1:
//                    mTvPunchNormal.setVisibility(View.VISIBLE);
//                    break;
//                case 2:
//                    mTvPunchMissingCard.setVisibility(View.VISIBLE);
//                    mLlTurnDown.setVisibility(View.VISIBLE);
//                    break;
//                case 3:
//                    mTvPunchUnderReview.setVisibility(View.VISIBLE);
//                    break;
//                case 4:
//                    mLlTurnDown.setVisibility(View.VISIBLE);
//                    mReason.setVisibility(View.VISIBLE);
//                    mReason.setText("驳回原因：" + classInfo.getRejectReason());
//                    break;
//                default:
//                    break;
//            }
//            mIvHaveAClass.setVisibility(!TextUtils.isEmpty(classInfo.getImg()) ? View.VISIBLE : View.GONE);
//            if (!TextUtils.isEmpty(classInfo.getImg())) {
//                GlideApp.with(getContext())
//                        .load(classInfo.getImg())
//                        .transform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners((int) getResources().getDimension(R.dimen.dp_10))))
//                        .into(mIvHaveAClass);
//            }
        }
    }
}
